package com.lh0811.forge.pserv.uacs.server.adapter.controller;

import com.github.pagehelper.PageInfo;
import com.lh0811.forge.dependency.basic_web.constant.AuthConstant;
import com.lh0811.forge.dependency.basic_web.response.ServerResponse;
import com.lh0811.forge.dependency.security.client.component.annotation.HasUrl;
import com.lh0811.forge.pserv.uacs.api.param.UacsPlateTenantInfoCreateParam;
import com.lh0811.forge.pserv.uacs.api.param.UacsPlateTenantInfoQueryListParam;
import com.lh0811.forge.pserv.uacs.api.param.UacsPlateTenantInfoQueryPageParam;
import com.lh0811.forge.pserv.uacs.api.param.UacsPlateTenantInfoUpdateParam;
import com.lh0811.forge.pserv.uacs.api.vo.UacsPlateTenantInfoQueryVo;
import com.lh0811.forge.pserv.uacs.server.service.PlateTenantService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Tag(name = "权限中心-平台租户管理")
@RestController
@RequestMapping("/forge/plate/v1/uacs/plate_tenant")
public class OpmsPlateTenantController {

    @Resource
    private PlateTenantService plateTenantService;

    // 创建租户信息
    @HasUrl
    @PutMapping("/create")
    @Operation(summary = "创建租户信息", parameters = {
            @Parameter(in = ParameterIn.HEADER, name = AuthConstant.TokenKey, description = "用户Token")
    })
    public ServerResponse plateTenantCreate(@RequestBody @Valid UacsPlateTenantInfoCreateParam param) throws Exception {
        plateTenantService.plateTenantCreate(param);
        return ServerResponse.createBySuccess();
    }

    // 删除租户信息
    @HasUrl
    @DeleteMapping("/delete/{tenantId}")
    @Operation(summary = "删除租户信息", parameters = {
            @Parameter(in = ParameterIn.HEADER, name = AuthConstant.TokenKey, description = "用户Token")
    })
    public ServerResponse plateTenantDelete(@PathVariable(value = "tenantId") Long tenantId) throws Exception {
        plateTenantService.plateTenantDelete(tenantId);
        return ServerResponse.createBySuccess();
    }

    // 修改租户信息
    @HasUrl
    @PostMapping("/update")
    @Operation(summary = "修改租户信息", parameters = {
            @Parameter(in = ParameterIn.HEADER, name = AuthConstant.TokenKey, description = "用户Token")
    })
    public ServerResponse plateTenantUpdate(@RequestBody @Valid UacsPlateTenantInfoUpdateParam param) throws Exception {
        plateTenantService.plateTenantUpdate(param);
        return ServerResponse.createBySuccess();
    }

    // 查询租户信息（分页）
    @HasUrl
    @GetMapping("/query/page")
    @Operation(summary = "查询租户信息（分页）", parameters = {
            @Parameter(in = ParameterIn.HEADER, name = AuthConstant.TokenKey, description = "用户Token")
    })
    public ServerResponse<PageInfo<UacsPlateTenantInfoQueryVo>> plateTenantQueryPage(@ParameterObject @Valid UacsPlateTenantInfoQueryPageParam param) throws Exception {
        return ServerResponse.createBySuccess("查询成功", plateTenantService.plateTenantQueryPage(param));
    }

    // 查询租户信息（分页）
    @HasUrl
    @GetMapping("/query/list")
    @Operation(summary = "查询租户信息（分页）", parameters = {
            @Parameter(in = ParameterIn.HEADER, name = AuthConstant.TokenKey, description = "用户Token")
    })
    public ServerResponse<List<UacsPlateTenantInfoQueryVo>> plateTenantQueryList(@ParameterObject @Valid UacsPlateTenantInfoQueryListParam param) throws Exception {
        return ServerResponse.createBySuccess("查询成功", plateTenantService.plateTenantQueryList(param));
    }

}
